<?php
require_once '../config/config.php';
$conn = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($conn->connect_errno) {
    die('数据库连接失败' . $conn->connect_error);
}
if (!empty($_REQUEST['url']) && !empty($_REQUEST['id'])) {
    if (!filter_var($_REQUEST['url'],FILTER_VALIDATE_URL)) {
        die("请输入正确的链接地址");
    }
    $stmt = $conn->prepare('update banner_list set url=? where id=?');
    $stmt->bind_param('si', $_REQUEST['url'], $_REQUEST['id']);
    $stmt->execute();

    if ($stmt->affected_rows === 1) {
        echo "<script>alert('更新成功,点击返回');window.location='bannerselect.php'</script>";
    } else {
        echo "<script>alert('更新失败,点击返回');window.location='bannerselect.php'</script>";
    }
} else {
    $stmt = $conn->prepare('select * from banner_list where id=?');
    $stmt->bind_param('i', $_REQUEST['id']);
    $stmt->execute();
    $stmt->bind_result($id, $src, $time, $url);
    $stmt->fetch();
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>修改界面</title>
    </head>
    <body>
        <form method="post">
            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
            <input type="text" name="url" value="<?php echo $url; ?>"/>
            <input type="submit" value="提交"/>
        </form>
    </body>
</html>
